import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/About',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/Cars',
    name: 'Cars',
    component: () => import('../views/Cars.vue')
  },
  {
    path: '/',
    name: 'Login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

var userLoginStatus = false;
router.beforeEach((to,from,next) => {
	var userLoginStatus = localStorage.getItem("token");
	if(to.name === "Login"){
		next()
	} else {
		if(userLoginStatus){
			next()
		} else {
			next('/')
		}
	}
})

export default router
